package de.dlrg.wms.controller.controllers.Test;

import static de.dlrg.wms.model.AgeClass.AgeClass;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import de.dlrg.wms.controller.controllers.AgeClassController;
import de.dlrg.wms.controller.controllers.DisciplineController;
import de.dlrg.wms.model.AgeClass;
import de.dlrg.wms.model.Discipline;

public class AgeClassAdder {

	@Autowired
	private AgeClassController ageClassController;
	@Autowired
	private DisciplineController disciplineController;

	private List<Discipline> disciplines;

	private void createOrUpdate(AgeClass ageClass) {
		this.ageClassController.createOrUpdate(ageClass);
	}

	private Discipline getDiscipline(int i) {
		return this.disciplines.get(i);
	}

	public void execute() {
		this.disciplines = this.disciplineController.readAll();
		{
			createOrUpdate(AgeClass().setName("unter 12 W")
					.addDiscipline(disciplines.get(1))
					.addDiscipline(disciplines.get(0)));
			createOrUpdate(AgeClass().setName("unter 12 M")
					.addDiscipline(disciplines.get(1))
					.addDiscipline(disciplines.get(0)));
			createOrUpdate(AgeClass().setName("ueber 12 W")
					.addDiscipline(disciplines.get(2))
					.addDiscipline(disciplines.get(3)));
			createOrUpdate(AgeClass().setName("ueber 12 M")
					.addDiscipline(disciplines.get(2))
					.addDiscipline(disciplines.get(3)));
			createOrUpdate(AgeClass().setName("15/16 M")
					.addDiscipline(disciplines.get(2))
					.addDiscipline(disciplines.get(3)));
			createOrUpdate(AgeClass().setName("15/16 W")
					.addDiscipline(disciplines.get(2))
					.addDiscipline(disciplines.get(3)));
			createOrUpdate(AgeClass().setName("17/18 M")
					.addDiscipline(getDiscipline(0))
					.addDiscipline(getDiscipline(1))
					.addDiscipline(getDiscipline(2))
					.addDiscipline(getDiscipline(3))
					.addDiscipline(getDiscipline(4))
					.addDiscipline(getDiscipline(5)));
			createOrUpdate(AgeClass().setName("17/18 W")
					.addDiscipline(getDiscipline(0))
					.addDiscipline(getDiscipline(1))
					.addDiscipline(getDiscipline(2))
					.addDiscipline(getDiscipline(3))
					.addDiscipline(getDiscipline(4))
					.addDiscipline(getDiscipline(5)));
		}
	}
}
